<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:insert="~{include :: header('配置')}" />
	<th:block th:insert="~{include :: select2-css}" />
</head>
<body>
    <div class="main-content">
        <form id="form-user-add" class="form-horizontal">
            <input name="deptId" type="hidden" id="treeId"/>
            <h4 class="form-header h4">配置</h4>
			<div class="row">
				<div class="col-sm-12">
					<div class="tabs-container">
						<ul class="nav nav-tabs">
							<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">需求跟踪</a></li>
							<li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">版本</a></li>
							<li class=""><a data-toggle="tab" href="#tab-3" onclick="queryIssueCategories()" aria-expanded="false">需求类别</a></li>
						</ul>
						<div class="tab-content">
							<div id="tab-1" class="tab-pane active">
								<div class="panel-body">
									<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="project:settings:add">
									    <i class="fa fa-plus"></i> 新增
									</a>
									<h4 class="form-header h4">跟踪标签</h4>
									<div class="checkbox check-box" th:each="tracker : ${trackerList}">
									    <label><input type="checkbox" th:value="${tracker.id}" th:checked="${tracker.isInChlog}"><i></i><span th:text="${tracker.name}">跟踪器名称</span></label>
									</div>
									<div class="row">
									    <div class="col-sm-offset-5 col-sm-10">
									        <button type="button" class="btn btn-sm btn-primary" onclick="submitTracker()"><i class="fa fa-check"></i>保 存</button>
									    </div>
									</div>
								</div>
							</div>
							<div id="tab-2" class="tab-pane">
								<div class="panel-body">
								</div>
							</div>
							<div id="tab-3" class="tab-pane">
								<div class="panel-body">
									<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="project:settings:add">
									    <i class="fa fa-plus"></i> 新增
									</a>
									<h4 class="form-header h4">需求类别</h4>

									<div class="col-sm-12 select-table table-striped">
									    <table id="bootstrap-table"></table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
        </form>
    </div>
      
	<th:block th:insert="~{include :: footer}" />
	<th:block th:insert="~{include :: select2-js}" />
	<script>
	    var prefix = ctx + "project/setting";
		
		$(document).ready(function () {
		});

		$(function() {
			// 跟踪标签表格配置
			var options = {
			    createUrl: prefix + "/addTracker",
			    modalName: "跟踪标签",
			    width: 600,
			    height: 400
			};
			$.table.init(options);
			
			
			queryIssueCategories();
		})
		
		function queryIssueCategories(){
			// 需求类别表格配置
			var issueCategoriesOptions = {
			    id: "bootstrap-table",
			    modalName: "需求类别",
			    url: prefix + "/categories/list",
			    createUrl: prefix + "/categories/add",
			    updateUrl: prefix + "/categories/edit/{id}",
			    removeUrl: prefix + "/categories/remove",
			    columns: [{
			        field: 'id',
			        title: 'ID',
			        visible: false
			    }, {
			        field: 'name',
			        title: '分类名称'
			    }, {
			        field: 'projectId',
			        title: '项目ID',
			        visible: false
			    }, {
			        title: '操作',
			        align: 'center',
			        formatter: function(value, row, index) {
			            var actions = [];
			            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
			            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-trash"></i>删除</a>');
			            return actions.join('');
			        }
			    }]
			};
			$.table.init(issueCategoriesOptions);
		}
		
		function submitTracker() {
		    // 收集所有选中的跟踪器ID
		    var selectedTrackerIds = [];
		    $('.checkbox.check-box input[type="checkbox"]:checked').each(function() {
		        selectedTrackerIds.push($(this).val());
		    });
		    
		    // 发送到后台
		    $.operate.post(prefix + "/updateIsInChlog", { trackerIds: selectedTrackerIds.join(',') });
		}
    </script>
</body>
</html>